Add draft for passing metadata to dependencies
authorPierre Krieger <pierre.krieger1708@gmail.com>
Mon, 27 Oct 2014 16:22:14 +0000 (17:22 +0100)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 5 Nov 2014 19:37:34 +0000 (11:37 -0800)
src/cargo/ops/cargo_rustc/mod.rs

index b0b0d4e4e01d3b8b51162394e3e04a6dcd8c18fd..72a6f3ec1f2436283f8f49ed0533b4633c2e91d8 100644 (file)
@@ -473,6 +473,15 @@ fn prepare_execute_custom_build(pkg: &Package, root_pkg: &Package, target: &Targ
         None => {}
     }
 
+    // building the list of all possible `build/$pkg/output` files
+    // whether they exist or not will be checked during the work
+    let command_output_files = {
+        let layout = cx.layout(pkg, KindForHost);
+        cx.dep_targets(pkg).iter().map(|&(pkg, _)| {
+            layout.build(pkg).join("output")
+        }).collect::<Vec<_>>()
+    };
+
     // Building command
     let pkg = pkg.to_string();
     let work = proc(desc_tx: Sender<String>) {
@@ -485,6 +494,31 @@ fn prepare_execute_custom_build(pkg: &Package, root_pkg: &Package, target: &Targ
                 }))
         }
 
+        // loading each possible custom build output file in order to get their metadata
+        let _metadata = {
+            let mut metadata = Vec::new();
+
+            for flags_file in command_output_files.into_iter() {
+                match File::open(&flags_file) {
+                    Ok(flags) => {
+                        let flags = try!(CustomBuildCommandOutput::parse(
+                            BufferedReader::new(flags), pkg.as_slice()));
+                        metadata.extend(flags.metadata.into_iter());
+                    },
+                    Err(_) => ()  // the file doesn't exist, probably means that this pkg
+                                  // doesn't have a build command
+                }
+            }
+
+            metadata
+        };
+
+        // TODO: ENABLE THIS CODE WHEN `links` IS ADDED
+        /*let mut p = p;
+        for (key, value) in metadata.into_iter() {
+            p = p.env(format!("DEP_{}_{}", PUT LINKS VALUES HERE, value), value);
+        }*/
+
         let output = try!(p.exec_with_output().map_err(|mut e| {
             e.msg = format!("Failed to run custom build command for `{}`\n{}",
                             pkg, e.msg);